package data

import (
	"061/Sgame/server/game/gameConfig"
	"061/Sgame/server/game/model"
	"time"
)

const (
	MapBuildSysFortress = 50 //系统要塞
	MapBuildSysCity     = 51 //系统城市
	MapBuildFortress    = 56 //玩家要塞
)

// 角色建筑
type MapRoleBuild struct {
	Id         int       `gorm:"column:id;primaryKey"`
	RId        int       `gorm:"column:rid"`
	Type       int8      `gorm:"column:type;comment:建筑类型"`
	Level      int8      `gorm:"column:level;comment:建筑等级"`
	OPLevel    int8      `gorm:"column:op_level;comment:建筑操作等级"` //操作level
	X          int       `gorm:"column:x"`
	Y          int       `gorm:"column:y"`
	Name       string    `gorm:"column:name;comment:名称"`
	Wood       int       `gorm:"-"`
	Iron       int       `gorm:"-"`
	Stone      int       `gorm:"-"`
	Grain      int       `gorm:"-"`
	Defender   int       `gorm:"-"`
	CurDurable int       `gorm:"column:cur_durable;comment:当前耐久"`
	MaxDurable int       `gorm:"column:max_durable;comment:最大耐久"`
	OccupyTime time.Time `gorm:"column:occupy_time;comment:占领时间"`
	EndTime    time.Time `gorm:"column:end_time;comment:建造、升级、拆除结束时间"` //建造或升级完的时间
	GiveUpTime int64     `gorm:"column:giveUp_time;comment:放弃时间"`
}

func (m *MapRoleBuild) TableName() string {
	return "map_role_build"
}

func (m *MapRoleBuild) ToModel() interface{} {
	p := model.MapRoleBuild{}
	p.RNick = "111"
	p.UnionId = 0
	p.UnionName = ""
	p.ParentId = 0
	p.X = m.X
	p.Y = m.Y
	p.Type = m.Type
	p.RId = m.RId
	p.Name = m.Name

	p.OccupyTime = m.OccupyTime.UnixNano() / 1e6
	p.GiveUpTime = m.GiveUpTime * 1000
	p.EndTime = m.EndTime.UnixNano() / 1e6

	p.CurDurable = m.CurDurable
	p.MaxDurable = m.MaxDurable
	p.Defender = m.Defender
	p.Level = m.Level
	p.OPLevel = m.OPLevel
	return p
}

func (m *MapRoleBuild) Init() {
	cfg := gameConfig.MapBuildConf.BuildConfig(m.Type, m.Level)
	if cfg != nil {
		m.Name = cfg.Name
		m.Level = cfg.Level
		m.Type = cfg.Type
		m.Wood = cfg.Wood
		m.Iron = cfg.Iron
		m.Stone = cfg.Stone
		m.Grain = cfg.Grain
		m.MaxDurable = cfg.Durable
		m.CurDurable = cfg.Durable
		m.Defender = cfg.Defender
	}
}
